<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018\11\27 0027
 * Time: 15:47
 */
namespace app\common\behavior;

use think\Config;
use think\Request;

class Language{

    public function run(){

        $request = Request::instance();

        $languageMap = Config::get("language_map");
        $host = $request->host();
        $language = 'en-us';
        if(!empty($languageMap[$host])){
            $language = $languageMap[$host];
        }

        $databaseMap = Config::get("database_map");
        $database = 'hanmameiguo';
        if(!empty($databaseMap[$host])){
            $database = $databaseMap[$host];
        }

        $routerMap = Config::get("routermap");
        $routerFile = 'routermap';
        if(!empty($routerMap[$host])){
            $routerFile = $routerMap[$host];
        }

        $siteMap = Config::get("sitemap");
        $siteMapFile = 'sitemap';
        if(!empty($siteMap[$host])){
            $siteMapFile = $siteMap[$host];
        }

        $altMap = Config::get("alt_map");
        $altMapFile = 'altmap';
        if(!empty($altMap)){
            $altMapFile = $altMap[$host];
        }

        Config::set("default_lang",$language);
        Config::set('database.database',$database);
        Config::set("router_file",$routerFile);
        Config::set("site_map_file",$siteMapFile);
        Config::set("altmap_file",$altMapFile);
    }
}